<!DOCTYPE html>
<html>
<head>
    <title>Mesh Slicing</title>

    <script src="js/verb.min.js"></script>
    <script src="js/three.min.js"></script>
    <script src="js/verbToThreeConversion.js"></script>
    <script src="js/OrbitControls.js"></script>
    <script src="js/codemirror.js"></script>
    <script src="js/javascript.js"></script>
    <script src="js/threeBasic.js"></script>

    <link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300' rel='stylesheet' type='text/css'>

    <link rel="stylesheet" href="css/codemirror.css">
    <link rel="stylesheet" href="css/example.css">
    <link rel="stylesheet" href="css/colorforth.css">
</head>
<body>

<div id="button">Show/Hide Code</div>
<div id="viewer" class="col">
    <div id="title"></div>
</div>
<div id="code-container" class="col scroll-y"></div>

</body>
<script id="script">

	setupScene();

	var degree = 3
		, knots = [0, 0, 0, 0, 0.333, 0.666, 1, 1, 1, 1]
		, pts = [ 	[ [0, 0, -10], 	[10, 0, 0], 	[20, 0, 0], 	[30, 0, 0] , 	[40, 0, 0], [50, 0, 10] ],
					[ [0, -10, 0], 	[10, -10, 10], 	[20, -10, 10], 	[30, -10, 0] , [40, -10, 0], [50, -10, 0]	],
					[ [0, -20, 0], 	[10, -20, 10], 	[20, -20, 10], 	[30, -20, 0] , [40, -20, -2], [50, -20, -12] 	],
					[ [0, -30, 0], 	[10, -30, 0], 	[20, -30, -23], 	[30, -30, 0] , [40, -30, 0], [50, -30, 0]     ],
					[ [0, -40, 0], 	[10, -40, 0], 	[20, -40, 0], 	[30, -40, 4] , [40, -40, -20], [50, -40, 0]     ],
					[ [0, -50, 12], [10, -50, 0], 	[20, -50, 20], 	[30, -50, 0] , [50, -50, -10], [50, -50, -15]     ],     ];

	var srf = verb.geom.NurbsSurface.byKnotsControlPointsWeights( degree, degree, knots, knots, pts );

	addMeshToScene( srf.toThreeGeometry(), null, true );

    var mesh = srf.tessellate();
	var res;
	var runs = 1;

	var d1 = Date.now();

	for (var i = 0 ; i < runs; i++){
		res = verb.eval.Intersect.meshSlices( mesh, -15, 15, 1 );
	}

    console.log( res );

	var d2 = Date.now();

	console.log( res.length," slices in ", (d2 - d1) / runs, " ms");

	for (var i = 0; i < res.length; i++){
	    for (var j = 0; j < res[i].length; j++){
            var pwl = res[i][j].map(function(x){ return x.point; });
		    addCurveToScene( pointsAsGeometry( pwl ));
	    }
	}

	renderScene();

</script>

<script src="js/example.js"></script>

</html>